﻿using System;
using System.ComponentModel;
using System.Text.RegularExpressions;
using System.Windows;

namespace Serietheque.Fenetres
{
    /// <summary>
    /// Logique d'interaction pour Renommer.xaml
    /// </summary>
    public partial class Renommer : Window, INotifyPropertyChanged
    {
        private string m_textA;
        private string m_textB;

        public string TextA
        {
            get { return m_textA; }
            set
            {
                if (value != this.m_textA)
                {
                    this.m_textA = value;
                    NotifyPropertyChanged("TextA");
                }
            }
        }

        public string TextB
        {
            get { return m_textB; }
            set
            {
                if (value != this.m_textB)
                {
                    this.m_textB = value;
                    NotifyPropertyChanged("TextB");
                }
            }
        }

        public Renommer()
        {
            InitializeComponent();
            this.DataContext = this;
        }

        public Renommer(string _textA)
            : this()
        {
            m_textA = m_textB = _textA;
        }

        public Renommer(string _textA, string _textB)
            : this()
        {
            m_textA = _textA;
            m_textB = _textB;
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Regex regex3 = new Regex(@"([#/\$!*:<>])");
            m_textB = textBox1.Text;

            if (String.IsNullOrWhiteSpace(m_textB))
                MessageBox.Show("Vous n'avez pas saisis de texte");
            else if (regex3.IsMatch(m_textB))
                MessageBox.Show("Le texte contient des caractères incorrecte");
            else
                Close();
        }

        #region INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(info));
        }

        #endregion INotifyPropertyChanged
    }
}